package com.huifaapp.mall.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.huifaapp.mall.R;

import java.util.List;

/**
 * Created by duanyu on 2018/1/17.
 */

public class Tmall_homepageAdapter extends RecyclerView.Adapter<Tmall_homepageAdapter.MyViewHolder> implements View.OnClickListener{
    private Context context;
    private List<String> oeMimgeUrllist;

    public Tmall_homepageAdapter(Context context, List<String> oeMimgeUrllist) {
        this.context = context;
        this.oeMimgeUrllist = oeMimgeUrllist;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View recyclerViewItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.itme_homepeg_prefecture, parent, false);
        recyclerViewItem.setOnClickListener(this);
        return new MyViewHolder(recyclerViewItem);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Glide.with(context).load(oeMimgeUrllist.get(position)).into(holder.jDcomOME_imge5);
        holder.itemView.setTag(position);
    }

    @Override
    public void onClick(View v) {
        if (mMyItemclickListener != null) {
            mMyItemclickListener.itemclick(v, (Integer) v.getTag());
        }
    }

    public interface MyItemclickListener {
        void itemclick(View view, int position);


    }
    public MyItemclickListener mMyItemclickListener;

    public void setmMyItemclickListener(MyItemclickListener mMyItemclickListener) {
        this.mMyItemclickListener = mMyItemclickListener;
    }
    @Override
    public int getItemCount() {
        return oeMimgeUrllist.size();
    }
    class MyViewHolder extends RecyclerView.ViewHolder {

        private final ImageView jDcomOME_imge5;

        public MyViewHolder(View itemView) {
            super(itemView);
            jDcomOME_imge5 = (ImageView) itemView.findViewById(R.id.JDcomOME_imge5);
        }
    }
}
